package me.w70.bot.wrappers;

import java.awt.Point;

import me.w70.bot.Bot;
import me.w70.bot.methods.Calc;
import me.w70.hooks.Tile;

/**
 * Created by IntelliJ IDEA. User: Jan Ove / Kosaki Date: 06.apr.2009 Time:
 * 15:36:48 <p/> Had to call it Obj because everything in Java derive from
 * Object :/
 */
public class PhysicalObject {
	protected long UID;

	protected me.w70.hooks.PhysicalObject physObj;

	public PhysicalObject(me.w70.hooks.PhysicalObject physObj) {
		this.physObj = physObj;
		this.UID = physObj.getUID();

	}

	public long getUID() {
		return UID;
	}

	public int getID() {
		return (int) (UID >>> 32 & 0x7fffffff);
	}

	/**
	 * @return type: 2 is an object that don't move 3 is an item laying on the
	 *         floor.
	 */
	public int getType() {
		return (int) (UID >> 29) & 0x3;
	}

	public Tile getLocation() {
		return new Tile(
				(int) (Bot.methods.getClient().getBaseX() + (UID & 0x7f)),
				(int) (Bot.methods.getClient().getBaseY() + (UID >> 7 & 0x7f)));
	}

	public Point getScreenPos() {
		return Calc.tileToScreen(getLocation());
	}

	public void doAction(String actionContains) {
		Point screenLoc = getScreenPos();
		if (!Calc.onScreen(screenLoc)) {
			Bot.methods.setCameraAngleTo(getLocation());
		}
		screenLoc = getScreenPos();
		Bot.methods.moveMouse(screenLoc, 2, 2);
		Bot.methods.wait(Bot.methods.random(30, 100));
		Bot.methods.atMenu(actionContains);
	}

	public boolean isStatic() {
		return getType() == 2;
	}
}
